﻿package com.d4p.util
{
	import flash.display.Sprite;

	public class FixedImage extends Sprite
	{
		public function FixedImage()
		{
			super();
		}
		public static function setFixedImage(mc:Object, mcW:Number, mcH:Number, setW:int, setH:int, full:Boolean = false):void
		{
			var _Height:int;
			var _Width:int;
			var _Per:Number = setW / setH;
			var imgPer:Number = mcW / mcH;
			var imgX:int = 0;
			var imgY:int = 0;
			
			if (full) {
				if (imgPer > _Per) {
					_Width = Math.round(mcW * (setH / mcH));
					_Height = setH;			
					imgX = Math.round((setW * .5) - (setW * .5));
					imgY = 0;
				} else {
					_Width = setW;
					_Height = Math.round(mcH * (setW / mcW));			
					imgX = 0;
					imgY = Math.round((setH * .5) - (_Height * .5));
				}
			} else {
				if (imgPer < _Per) {
					_Width = Math.round(mcW * (setH / mcH));
					_Height = setH;			
					imgX = Math.round((setW * .5) - (_Width * .5));
					imgY = 0;
				} else {
					_Width = setW;
					_Height = Math.round(mcH * (setW / mcW));			
					imgX = 0;
					imgY = Math.round((setH * .5) - (_Height * .5));
				}
			}
			
			mc.width = _Width;
			mc.height = _Height;
			mc.x = imgX;
			mc.y = imgY;
		}
	}
}